package cn.topevery.garden.wapi.controller;

import cn.topevery.garden.dal.logic.ProjStageFileCodeLogic;
import cn.topevery.garden.entity.dto.ProjStageFileCodeDTO;
import cn.topevery.garden.entity.po.ProjStageFileCode;
import cn.topevery.garden.entity.query.ProjStageFileCodeQuery;
import cn.topevery.garden.entity.vo.ProjStageFileCodeVO;
import cn.topevery.garden.framework.util.CurrentUserUtil;
import hw.topevery.framework.DataFillHelper;
import hw.topevery.framework.db.entity.DataPager;
import hw.topevery.framework.util.ExcelUtil;
import hw.topevery.framework.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * 项目阶段附件编码维护表
 *
 * @author code-generate
 * @date 2022-11-02
 */
@Api(tags = "工程项目-项目阶段附件编码维护表")
@RestController
@RequestMapping("/projStageFileCode")
public class ProjStageFileCodeController extends BaseController {


    @Autowired
    ProjStageFileCodeLogic projStageFileCodeLogic;

    /**
     * 获取项目阶段附件编码维护表分页列表
     *
     * @param query
     * @return
     */
    @ApiOperation(value = "获取项目阶段附件编码维护表页列表")
    @GetMapping("/listPage")
    public JsonResult<DataPager<ProjStageFileCodeVO>> listPage(ProjStageFileCodeQuery query) {
        return JsonResult.ok(projStageFileCodeLogic.listPage(query));
    }

    @ApiOperation("新增/编辑 项目阶段附件编码维护表信息")
    @PostMapping("/saveOrUpdate")
    public JsonResult<Boolean> saveOrUpdate(@Valid @RequestBody ProjStageFileCodeDTO dto) {
        return JsonResult.ok(projStageFileCodeLogic.saveOrUpdate(getUser().userId, dto));
    }

    @ApiOperation("根据id获取详情")
    @GetMapping("/getById")
    public JsonResult<ProjStageFileCode> getById(@RequestParam(value = "id") Integer id) {
        return JsonResult.ok(projStageFileCodeLogic.getEntity(id));
    }

    @ApiOperation("根据id获取详情")
    @GetMapping("/getByStageTypeCode")
    public JsonResult<List<ProjStageFileCodeVO>> getByStageTypeCode(@RequestParam(value = "stageTypeCode") String stageTypeCode) {
        return JsonResult.ok(projStageFileCodeLogic.getByStageTypeCode(stageTypeCode));
    }

    @ApiOperation("根据自增ID批量删除")
    @PostMapping("/deleteBatchById")
    public JsonResult<Boolean> deleteBatchById(@RequestBody Integer[] ids) {
        projStageFileCodeLogic.deleteBatchById(CurrentUserUtil.getUser().userId,ids);
        return JsonResult.ok(true);
    }

    @ApiOperation("导出项目阶段附件编码维护表信息")
    @GetMapping("/export")
    public void export(ProjStageFileCodeQuery query, HttpServletResponse response) {
        List<ProjStageFileCodeVO> list = projStageFileCodeLogic.listPage(query).records;
        ExcelUtil.exportExcel(list, "项目阶段附件编码维护表", "sheet1", ProjStageFileCodeVO.class, "项目阶段附件编码维护表", response);
    }

}
